// packageA/mycomponent/goodsComponent/plugin/delivery_address/delivery_address.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    addressName: "",
    showAddressList: false,
  },
  lifetimes: {
    attached() {
      this.txtComputed()
    },
    ready() {},
    detached() {

    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    showAddressShow() {
      this.setData({
        showAddressList: true
      })
    },
    confirmSelectAddress(e) {
      let item = e.detail;
      this.yzaddressInfo = item;
      let addressq = `${this.yzaddressInfo.province || ''}${this.yzaddressInfo.city || ''}${this.yzaddressInfo.district || ''}${this.yzaddressInfo.street || ''}${this.yzaddressInfo.address || ''}`;
      this.setData({
        addressName: addressq || '请选择收货地址',
        showAddressList: false
      })
      this.tapMrAdress(item);
      this.triggerEvent('setGoodAddress',item)
    },
    // 选中后设置成默认地址
    tapMrAdress(item){
      let json = {
        username: item.username,
        mobile: item.mobile,
        province: item.province,
        city: item.city,
        district: item.district,
        address: item.address,
        isdefault: 1,
        address_id: item.id,
        street: item.street||''
      };
      let urlStr = app.getNetAddresss("member.member-address.update");
      app._postNetWork({
        url: urlStr,
        data: json,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            
          }
        },
      });
    },
    txtComputed() {
      // 默认的情况下显示 默认地址
      let { province = '', city = '', district = '', street = '', address = '' } = this.data.datas.address;
      let addressq = `${province}${city}${district}${street}${address}`;
      this.setData({
        addressName: addressq || '请选择收货地址'
      })
      this.triggerEvent('setGoodAddress',this.data.datas.address)
    },
  }
})